package com.hnqcgczy.controller;

import com.hnqcgczy.service.IShopCartService;
import com.hnqcgczy.service.impl.ShopCartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delcart")
public class DelShopCartServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //判断用户登陆状态
        String tuId=(String)req.getSession().getAttribute("tuId");
        //判断如果tuId为null，跳转登陆
        if(tuId==null){
            resp.sendRedirect("/login.jsp");
            return;
        }

        //获取删除的购物车编号
        String tsId=req.getParameter("tsId");
        //调用服务层执行删除方法
        IShopCartService cartService=new ShopCartServiceImpl();
        cartService.deleteShopCart(Integer.parseInt(tsId));

        //跳转到我的购物车页
        resp.sendRedirect("/shopCart");
    }
}
